fix: render gap.py invalid-AD debug log without raising TypeError#220
Merged
Conversation
The malformed-AD debug log used three %s placeholders but only passed two arguments, so any DEBUG-level handler raised "TypeError: not enough arguments for format string" while formatting the record. Add the missing AD `length` argument so the message renders cleanly and includes useful diagnostic context. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #220 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 248 248
Branches 37 37
=========================================
Hits 248 248 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a debug-log format string mismatch in the GAP advertisement parser so malformed AD structures can be logged at DEBUG level without raising a TypeError, and adds a regression test to ensure future log formatting errors are caught.
Changes:
- Fix
_LOGGER.debug(...)call in_uncached_parse_advertisement_bytesby passing the missinglengthargument and making the placeholder label explicit (length=%s). - Add a pytest regression test that triggers the invalid-AD branch and renders captured log records to ensure log formatting remains valid.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/bluetooth_data_tools/gap.py |
Fixes the debug log argument/placeholder mismatch by including length in the log call. |
tests/test_gap.py |
Adds a regression test that exercises the malformed AD path and forces log message rendering to catch formatting errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bdraco
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix a stale format-string mismatch in the debug log emitted when
_uncached_parse_advertisement_bytesrejects a malformed BLE GAP AD structure.Why
The message string had three
%splaceholders but the call only passedoffsetandgap_bytes. Any handler attached atDEBUGlevel forbluetooth_data_tools.gapraised:while rendering the record. The parser itself kept running (logging swallows the formatting error) but the stderr noise is misleading and the diagnostic message is unusable.
How
lengthas the third argument and rename the placeholder tolength=%s, which is the most actionable hint when the AD claims more bytes than remain in the buffer.lru_cachedoesn't short-circuit) and renders every captured record — a future format-string mismatch will fail the test.Testing
pytest tests/ --ignore=tests/benchmarks→ 64 passed.🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 15 insertions(+), 1 deletion(-)
Code scan: clean
Tests: failed ([Errno 13] Permission denied: 'pytest')
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline